#include "csv_util.h"
#include "grtcirc.h"
#include "strptime.h"
+#include "jeeps/gpsmath.h"
#define MYNAME "CSV_UTIL"
#define EXCEL_TO_TIMET(a) ((a - 25569.0) * 86400.0)
#define TIMET_TO_EXCEL(a) ((a / 86400.0) + 25569.0)
+#define GPS_DATUM_WGS84 118
/****************************************************************************/
/* obligatory global struct */
xcsv_file.type = ff_type_file;
xcsv_file.mkshort_handle = mkshort_new_handle();
+ xcsv_file.gps_datum = GPS_DATUM_WGS84;
}
/*****************************************************************************/
s = csv_lineparse(NULL, xcsv_file.field_delimiter, "",
linecount);
}
+ if ((xcsv_file.gps_datum > -1) && (xcsv_file.gps_datum != GPS_DATUM_WGS84)) {
+ double alt;
+ GPS_Math_Known_Datum_To_WGS84_M(wpt_tmp->latitude, wpt_tmp->longitude, 0.0,
+ &wpt_tmp->latitude, &wpt_tmp->longitude, &alt, xcsv_file.gps_datum);
+ }
waypt_add(wpt_tmp);
}
int i;
field_map_t *fmp;
queue *elem, *tmp;
+ double latitude, longitude;
if ( oldlon < 900 ) {
pathdist += radtomiles(gcdist(RAD(oldlat),RAD(oldlon),
RAD(wpt->latitude),RAD(wpt->longitude)));
}
- oldlon = wpt->longitude;
- oldlat = wpt->latitude;
+ longitude = oldlon = wpt->longitude;
+ latitude = oldlat = wpt->latitude;
if (xcsv_file.field_delimiter && strcmp(xcsv_file.field_delimiter, "\\w") == 0)
write_delimiter = " ";
description = xstrdup(odesc);
xfree(odesc);
}
+ if ((xcsv_file.gps_datum > -1) && (xcsv_file.gps_datum != GPS_DATUM_WGS84)) {
+ double alt;
+ GPS_Math_WGS84_To_Known_Datum_M(latitude, longitude, 0.0,
+ &latitude, &longitude, &alt, xcsv_file.gps_datum);
+ }
i = 0;
QUEUE_FOR_EACH(xcsv_file.ofield, elem, tmp) {
char *obuff;
- double lat = wpt->latitude;
- double lon = wpt->longitude;
+ double lat = latitude;
+ double lon = longitude;
/*
* A klunky concept. This should evaluate to true for any
* field if we think we don't have realistic value for it.
#include <ctype.h>
#include "defs.h"
#include "csv_util.h"
+#include "jeeps/gpsmath.h"
#if CSVFMTS_ENABLED
#define MYNAME "XCSV"
static char *snuniqueopt = NULL;
char *prefer_shortnames = NULL;
char *xcsv_urlbase = NULL;
+static char *opt_datum;
static const char *intstylebuf = NULL;
{"prefer_shortnames", &prefer_shortnames,
"Use shortname instead of description",
NULL, ARGTYPE_BOOL, ARG_NOMINMAX },
+ {"datum", &opt_datum, "GPS datum (def. WGS 84)",
+ NULL, ARGTYPE_STRING, ARG_NOMINMAX},
ARG_TERMINATOR
};
cet_convert_init(p, 1);
xfree(p);
} else
+
+ if (ISSTOKEN(sbuff, "DATUM")) {
+ p = csv_stringtrim(&sbuff[8], "\"", 1);
+ xcsv_file.gps_datum = GPS_Lookup_Datum_Index(p);
+ is_fatal(xcsv_file.gps_datum < 0, MYNAME ": datum \"%s\" is not supported.", p);
+ xfree(p);
+ } else
if (ISSTOKEN(sbuff, "IFIELD")) {
key = val = pfc = NULL;
}
xcsv_file.xcsvfp = gbfopen(fname, "r", MYNAME);
+ if (opt_datum) {
+ xcsv_file.gps_datum = GPS_Lookup_Datum_Index(opt_datum);
+ is_fatal(xcsv_file.gps_datum < 0, MYNAME ": datum \"%s\" is not supported.", opt_datum);
+ }
}
setshort_badchars(xcsv_file.mkshort_handle, xcsv_file.badchars);
}
-
+ if (opt_datum) {
+ xcsv_file.gps_datum = GPS_Lookup_Datum_Index(opt_datum);
+ is_fatal(xcsv_file.gps_datum < 0, MYNAME ": datum \"%s\" is not supported.", opt_datum);
+ }
}
static void